﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PlanB.ShareDove.ConferenceOrganization.ServiceLayer.ServiceFacade.Entities;
using PlanB.ShareDove.ConferenceOrganization.BusinessLayer.DataLayerInterface.Entities;

namespace PlanB.ShareDove.ConferenceOrganization.ServiceLayer.ServiceFacade.Transformations
{

    /// <summary>
    /// This class cointains methods for transforming the Conference Entities to the Lightweight conference entities, 
    /// which are suitable for using in web services
    /// </summary>
    public static class EntityTransformers
    {
        /// <summary>
        /// Transforms the ConferenceSession object to the LightWeight (flattened) Session object, suitable for 
        /// transporting through the services
        /// </summary>
        /// <param name="conferenceSession">ConferenceSession object to be transformed</param>
        /// <returns>Lightweight Session object</returns>
        public static ConferenceSessionLite TransformSessionToLite(ConferenceSession conferenceSession)
        {
            ConferenceSessionLite session = new ConferenceSessionLite();

            session.ID = conferenceSession.Id;
            session.Title = conferenceSession.Title;
            session.Abstract = conferenceSession.Abstract;
            session.Slot = conferenceSession.Slot;
            session.Duration = conferenceSession.Duration;
            session.EndTime = conferenceSession.EndTime;
            session.RoomId = (conferenceSession.Room != null) ? conferenceSession.Room.Id : 0;
            session.RoomName = (conferenceSession.Room != null) ? conferenceSession.Room.Name : "";
            session.TrackId = (conferenceSession.Track != null) ? conferenceSession.Track.Id : 0;
            session.TrackName = (conferenceSession.Track != null) ? conferenceSession.Track.Name : "";

            if (conferenceSession.Speakers.Count() > 0)
            {
                ConferenceParticipant speaker = conferenceSession.Speakers.ToArray()[0];

                session.SpeakerName = speaker.Name;
                session.SpeakerCity = speaker.Address != null ? speaker.Address.City : "";
                session.SpeakerAddressLatitude = speaker.Address != null ? speaker.Address.Latitude : "";
                session.SpeakerAddressLongitude = speaker.Address != null ? speaker.Address.Longitude : "";

            }

            return (session);
        }


        /// <summary>
        /// Transforms the ConferencePerson object to the LightWeight (flattened) Person object, suitable for 
        /// transporting through the services
        /// </summary>
        /// <param name="conferencePerson">ConferencePerson object to be transformed</param>
        /// <returns>Lightweight Person object</returns>
        public static ConferencePersonLite TransformPersonToLite(ConferencePerson conferencePerson)
        {
            ConferencePersonLite person = new ConferencePersonLite();

            person.ID = conferencePerson.Id;
            person.AddressCity = conferencePerson.Address.City;
            person.AddressLatitude = conferencePerson.Address.Latitude;
            person.AddressLongitude = conferencePerson.Address.Longitude;
            person.Company = conferencePerson.Company == null ? "" : conferencePerson.Company.Name;
            person.Name = conferencePerson.Name;
            person.PersonTitle = conferencePerson.PersonTitle;
            person.PhotoUrl= conferencePerson.PhotoUrl;
            person.Sex = conferencePerson.Sex.ToString();

            return person;
        }

    }
}
